#!/bin/bash
# Build Freon Linux software from source.
# Version: 0.6.0
# (C) Chris Dorman, 2018-2020 GPLv3+

corecount="25"

#### Variables ###
mainmirror="http://mirror.freonlinux.com/source/packages"

# mirrors
mpfrmirror="https://ftp.gnu.org/gnu/mpfr"
mpcmirror="https://ftp.gnu.org/gnu/mpc"
gmpmirror="https://ftp.gnu.org/gnu/gmp"
binutilsmirror="https://ftp.gnu.org/gnu/binutils"
gccmirror="http://ftp.gnu.org/gnu/gcc/gcc-9.2.0"
nanomirror="https://www.nano-editor.org/dist/v3"
chttpdmirror="https://github.com/Pentium44/chttpd.git"
ftpmirror="https://github.com/Harlonxl/minFTPD.git"
harfbuzzmirror="http://deb.debian.org/debian/pool/main/h/harfbuzz"
ncursesmirror="https://ftp.gnu.org/pub/gnu/ncurses"
bashmirror="https://ftp.gnu.org/gnu/bash"
zlibmirror="https://zlib.net"
termcapmirror="https://ftp.gnu.org/gnu/termcap"
htopmirror="https://github.com/htop-dev/htop/archive"
islmirror="http://isl.gforge.inria.fr"
irciimirror="http://ircii.warped.com"
opensslmirror="https://www.openssl.org/source"
xlibmirror="https://www.x.org/archive/individual/lib"
xcbmirror="https://www.x.org/archive/individual/xcb"
libbsdmirror="https://libbsd.freedesktop.org/releases"
bz2mirror="https://sourceware.org/pub/bzip2"
freetypemirror="https://download.savannah.gnu.org/releases/freetype"
png16mirror="https://download.sourceforge.net/libpng"
stracemirror="https://gitlab.com/strace/strace.git"
elfutilsmirror="git://sourceware.org/git/elfutils.git"
gtk2mirror="https://download.gnome.org/sources/gtk+/2.24"
netsurfmirror="http://download.netsurf-browser.org/netsurf/releases/source-full"
xfemirror="https://netactuate.dl.sourceforge.net/project/xfe/xfe/1.43.2"
pangomirror="https://download.gnome.org/sources/pango/1.42"
fontconfigmirror="https://www.freedesktop.org/software/fontconfig/release"
hexchatmirror="https://dl.hexchat.net/hexchat"
pcmanfmmirror="https://downloads.sourceforge.net/pcmanfm"
idnmirror="https://ftp.gnu.org/gnu/libidn"
lynxmirror="https://invisible-mirror.net/archives/lynx/tarballs"
expatmirror="https://github.com/libexpat/libexpat/releases/download/R_2_2_7"
utillinuxmirror="https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.33"
foxmirror="ftp://ftp.fox-toolkit.org/pub"
glib2mirror="https://download.gnome.org/sources/glib/2.56"
cairomirror="https://www.cairographics.org/releases"
gdkpixbufmirror="http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/2.36"
atkmirror="http://ftp.gnome.org/pub/gnome/sources/atk/2.26"
gobjectintromirror="http://ftp.gnome.org/pub/gnome/sources/gobject-introspection/1.54"
selinuxmirror="http://deb.debian.org/debian/pool/main/libs/libselinux"
ffimirror="https://sourceware.org/ftp/libffi"
pcremirror="https://downloads.sourceforge.net/pcre"
fmmirror="https://downloads.sourceforge.net/pcmanfm"
menucachemirror="https://downloads.sourceforge.net/lxde"
notifymirror="http://ftp.gnome.org/pub/gnome/sources/libnotify/0.7"
fribidimirror="https://github.com/fribidi/fribidi/releases/download/v1.0.1"
saircdmirror="https://github.com/rg3/saircd"
sqlitemirror="https://www.sqlite.org/2020"

# filenames
gcc="gcc-9.2.0.tar.xz"
nano="nano-3.1.tar.xz"
ncurses="ncurses-6.1.tar.gz"
bash="bash-5.0.tar.gz"
zlib="zlib-1.2.11.tar.xz"
termcap="termcap-1.3.1.tar.gz"
htop="htop-2.2.0.tar.gz"
binutils="binutils-2.31.1.tar.xz"
gmp="gmp-6.1.2.tar.xz"
mpfr="mpfr-4.0.2.tar.xz"
mpc="mpc-1.1.0.tar.gz"
isl="isl-0.19.tar.xz"
ircii="ircii-20190117.tar.gz"
openssl="openssl-1.1.1h.tar.gz"
libbsd="libbsd-0.9.1.tar.xz"
bz2="bzip2-1.0.8.tar.gz"
freetype="freetype-2.10.4.tar.xz"
png16="libpng-1.6.37.tar.xz"
gtk2="gtk+-2.24.32.tar.xz"
netsurf="netsurf-all-3.10.tar.gz"
xcb="libxcb-1.13.tar.gz"
xcbutil="xcb-util-0.4.0.tar.gz"
xcbproto="xcb-proto-1.13.tar.gz"
xfe="xfe-1.43.2.tar.gz"
pango="pango-1.42.4.tar.xz"
fontconfig="fontconfig-2.13.1.tar.bz2"
hexchat="hexchat-2.12.4.tar.xz"
pcmanfm="pcmanfm-1.3.1.tar.xz"
lynx="lynx2.8.9rel.1.tar.gz"
idn="libidn-1.36.tar.gz"
expat="expat-2.2.7.tar.xz"
utillinux="util-linux-2.33.2.tar.xz"
fox="fox-1.6.57.tar.gz"
glib2="glib-2.56.4.tar.xz"
gobjectintro="gobject-introspection-1.54.1.tar.xz"
gdkpixbuf="gdk-pixbuf-2.36.11.tar.xz"
cairo="cairo-1.14.12.tar.xz"
pixman="pixman-0.34.0.tar.gz"
atk="atk-2.26.1.tar.xz"
pcre="pcre-8.43.tar.bz2"
selinux="libselinux_2.8.orig.tar.gz"
fm="libfm-1.2.5.tar.xz"
ffi="libffi-3.2.1.tar.gz"
menucache="menu-cache-1.1.0.tar.xz"
notify="libnotify-0.7.6.tar.xz"
fribidi="fribidi-1.0.1.tar.bz2"
harfbuzz="harfbuzz_2.3.1.orig.tar.bz2"
sqlite="sqlite-autoconf-3340000.tar.gz"
netcat="netcat-0.7.1.tar.bz2"
socat="socat-1.7.4.1.tar.gz"
nmap="nmap-7.91.tar.bz2"
overkill="0verkill-0.16.tar.gz"
readline="readline-8.1.tar.gz"

# work directories
tmpdir="`pwd`/pkgsrc"
softwaredir="`pwd`/src/rootfs"
freondir="/freon"
systemdir="`pwd`/system"
pkgbuilddir="`pwd`/pkgbuild"

# source directories
gccsrcdir=${gcc//.tar.xz}
nanosrcdir=${nano//.tar.xz}
ncursessrcdir=${ncurses//.tar.gz}
bashsrcdir=${bash//.tar.gz}
zlibsrcdir=${zlib//.tar.xz}
termcapsrcdir=${termcap//.tar.gz}
htopsrcdir=${htop//.tar.gz}
mpcsrcdir=${mpc//.tar.gz}
mpfrsrcdir=${mpfr//.tar.xz}
binutilssrcdir=${binutils//.tar.xz}
gmpsrcdir=${gmp//.tar.xz}
islsrcdir=${isl//.tar.xz}
irciisrcdir=${ircii//.tar.gz}
opensslsrcdir=${openssl//.tar.gz}
libbsdsrcdir=${libbsd//.tar.xz}
bz2srcdir=${bz2//.tar.gz}
freetypesrcdir=${freetype//.tar.xz}
png16srcdir=${png16//.tar.xz}
fontmiscsrcdir=${fontmisc//.tar.bz2}
font75dpisrcdir=${font75dpi//.tar.bz2}
font100dpisrcdir=${font100dpi//.tar.bz2}
gtk2srcdir=${gtk2//.tar.xz}
netsurfsrcdir=${netsurf//.tar.gz}
xfesrcdir=${xfe//.tar.gz}
pangosrcdir=${pango//.tar.xz}
fontconfigsrcdir=${fontconfig//.tar.bz2}
hexchatsrcdir=${hexchat//.tar.xz}
pcmanfmsrcdir=${pcmanfm//.tar.xz}
lynxsrcdir=${lynx//.tar.gz}
idnsrcdir=${idn//.tar.gz}
xcbsrcdir=${xcb//.tar.gz}
xcbutilsrcdir=${xcbutil//.tar.gz}
xcbprotosrcdir=${xcbproto//.tar.gz}
expatsrcdir=${expat//.tar.xz}
utillinuxsrcdir=${utillinux//.tar.xz}
foxsrcdir=${fox//.tar.gz}
glib2srcdir=${glib2//.tar.xz}
gdkpixbufsrcdir=${gdkpixbuf//.tar.xz}
cairosrcdir=${cairo//.tar.xz}
pixmansrcdir=${pixman//.tar.gz}
atksrcdir=${atk//.tar.xz}
gobjectintrosrcdir=${gobjectintro//.tar.xz}
ffisrcdir=${ffi//.tar.gz}
pcresrcdir=${pcre//.tar.bz2}
selinuxsrcdir=${selinux//.orig.tar.gz}
fmsrcdir=${fm//.tar.xz}
menucachesrcdir=${menucache//.tar.xz}
notifysrcdir=${notify//.tar.xz}
fribidisrcdir=${fribidi//.tar.bz2}
harfbuzzsrcdir=${harfbuzz//.tar.bz2}
sqlitesrcdir=${sqlite//.tar.gz}
netcatsrcdir=${netcat//.tar.bz2}
socatsrcdir=${socat//.tar.gz}
nmapsrcdir=${nmap//.tar.bz2}
overkillsrcdir=${overkill//.tar.gz}
readlinesrcdir=${readline//.tar.gz}

if [ ! -d "$tmpdir" ]; then
  echo "Warning: package source directory not found, creating."
  mkdir $tmpdir > /dev/null 2>&1
fi

case $1 in
	* ) echo "Building $1..."
		. $pkgbuilddir/$1.build;;
esac
